package com.woniuxy.propertyjava.controller;



import com.woniuxy.propertyjava.entity.Holdinformation;
import com.woniuxy.propertyjava.entity.Housinginformation;
import com.woniuxy.propertyjava.entity.PageBean;
import com.woniuxy.propertyjava.entity.ResponseResult;
import com.woniuxy.propertyjava.service.HoldinformationService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Holdinformation)表控制层
 *
 * @author makejava
 * @since 2022-07-05 22:53:09
 */
@RestController
public class HoldinformationController {
    /**
     * 服务对象
     */
    @Resource
    private HoldinformationService holdinformationService;

    /**
     * 分页查询
     *
     * @param holdinformation 筛选条件
     *     分页对象
     * @return 查询结果
     */
    @PostMapping("/holdinformation/{pageIndex}/{pageSize}")
    public ResponseResult<PageBean<Holdinformation>> queryByPage(
            @PathVariable("pageIndex") int pageIndex,
            @PathVariable("pageSize") int pageSize,
            @RequestBody Holdinformation holdinformation) {
        PageBean<Holdinformation>pageBean= holdinformationService.queryByPage(holdinformation, pageIndex, pageSize);
        return new ResponseResult<>(200,"ok",pageBean);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param hhid 主键
     * @return 单条数据
     */
    @GetMapping("/holdinformation/{hhid}")
    public ResponseEntity<Holdinformation> queryById(@PathVariable("hhid") Integer hhid) {
        return ResponseEntity.ok(this.holdinformationService.queryById(hhid));
    }
    /**
     * 新增数据
     *
     *  holdinformation 实体
     * @return 新增结果
     */
    @PostMapping("/holdinformation")
    public ResponseResult<Holdinformation> add(@RequestBody Holdinformation holdinformation) {
        holdinformationService.insert(holdinformation);
        return new ResponseResult<>(200, "ok", null);
    }

    /**
     * 编辑数据
     *
     * @param holdinformation 实体
     * @return 编辑结果
     */
    @PutMapping("/holdinformation")
    public ResponseResult<Holdinformation> edit(@RequestBody Holdinformation holdinformation) {
        holdinformationService.update(holdinformation);
        return new ResponseResult<>(200, "ok", null);
    }

    /**
     * 删除数据
     *
     *  hhid 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/holdinformation/{hhid}")
    public ResponseResult<Boolean> deleteById(@PathVariable("hhid") Integer hhid) {
        return new ResponseResult<>(200, "ok", holdinformationService.deleteById(hhid));
    }

}

